package com.andy.customerService.service.impl;

import com.andy.customerService.entity.Road;
import com.andy.customerService.enums.StatusEnum;
import com.andy.customerService.mapper.RoadMapper;
import com.andy.customerService.service.RoadService;
import com.andy.customerService.vo.JsonBaseResult;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 线路 服务实现类
 * </p>
 *
 * @author Andy
 * @since 2022-02-24
 */
@Service
public class RoadServiceImpl extends ServiceImpl<RoadMapper, Road> implements RoadService {

    @Autowired
    private RoadMapper roadMapper;

    /**
     * 添加线路
     *
     * @param road
     */
    @Override
    public JsonBaseResult<Object> addRoad(Road road) {
        JsonBaseResult<Object> result = new JsonBaseResult<>();
        roadMapper.insert(road);
        result.setResultStatus(StatusEnum.SUCCEED);
        return result;
    }

    /**
     * 修改线路
     */
    @Override
    public JsonBaseResult<Object> editRoad(Road road) {
        JsonBaseResult<Object> result = new JsonBaseResult<>();
        roadMapper.updateById(road);
        result.setResultStatus(StatusEnum.SUCCEED);
        return result;
    }

    /**
     * 根据角色获取线路
     * @param role
     */
    @Override
    public Road getRoadByRole(String role) {
        return roadMapper.selectOne(new LambdaQueryWrapper<Road>().eq(Road::getRole,role));
    }

    /**
     * 线路列表
     */
    @Override
    public JsonBaseResult<Object> roadList() {
        JsonBaseResult<Object> result = new JsonBaseResult<>();
        List<Road> roadList = roadMapper.selectList(null);
        result.setResult(roadList);
        return result;
    }
}
